package com.tsystems.tuni.sportplanet.dao;

import java.util.List;

import javax.persistence.Query;

import com.tsystems.tuni.sportplanet.entity.Company;
import com.tsystems.tuni.sportplanet.entity.Location;
import com.tsystems.tuni.sportplanet.entity.Sport;

public class LocationDAOImpl extends GenericDAOImpl<Location> implements
		LocationDAO {

	public LocationDAOImpl() {
		super();
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<Location> getAllLocationsBySport(Sport sport) {
		Query query = em
				.createQuery("select distinct g.location from Game g where g.sport=:sport");
		query.setParameter("sport", sport);
		return query.getResultList();
	}

	@Override
	public Location getCompanyLocation(Company company) {
		Query query = em
				.createQuery("select distinct d.location from Department d where d.company=:company");
		query.setParameter("company", company);
		return (Location) query.getSingleResult();
	}

}
